Clicking Render in RStudio defaults to render all qmd files in the
directory (“project”) and to render both html and pdf. To save time in
rendering, you can install quarto R package
install.packages("quarto")
library(quarto)
and then render just one file and choose the target to be html with
quarto_render("template2.qmd", output_format = "html")
and when you are ready to submit the pdf, use
quarto_render("template2.qmd", output_format = "pdf")
quarto R package will be soon available as pre-installed
in JupyterHub (you can first try library(quarto), and run
install.pckages only if needed).
If the rendering to pdf doesn’t work, you can print the html to pdf file, but do make sure to turn off “More setings -> Print headers and footers” to avoid accidentally printing your identity.
Instead of installing RStudio on your computer, you can use it in your web browser:
CS-E5710 - Bayesian Data Analysis (2023)RStudiolibrary(cmdstanr)This is cmdstanr version 0.6.0- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr- CmdStan path: /coursedata/cmdstan- CmdStan version: 2.33.0New Server and enter vdi.aalto.fiUbuntu 20.04RStudio in the search
bar, and click RStudio.Go to jupyter.cs.aalto.fi on your favorite
web-browser.
Log-in with your aalto username and password.
Select the
CS-E5710 - Bayesian Data Analysis (2023) -r-ubuntu:6.2.3-bayesda2023
server.
Select the notebooks folder in the left hand file
browser.
Select the git clone icon as seen in the screenshot
below.
In the text box type
https://github.com/avehtari/BDA_R_demos.git for python
demos replace BDA_R_demos.git with
BDA_Python_demos.git instead. Then click
clone.
Wait a while, there should be BDA_R_demos folder
under notebooks folder. Click on the
BDA_R_demos folder.
Click on the RStudio button on the right.
Now you should have an R-studio like interface in your
web-browser. Click on File -> Open File...
Click on notebooks and then select
BDA_R_demos folder.
Select a demo to run. Here we open the folder
demos_ch2 and then select demo2_1.R file and
click open. This should open the file in the window.
Select the contents of the file and click
Code -> Run Selected Line(s) as shown in the screenshot
below.
You should see the output of the code in the bottom right corner.
Instead of trying to download each file separately via the Github interface, it is recommended to use one of these options:
Aalto JupyterHub has all the R packages used in demos pre-installed. If you install R on your own computer, you can install all the packages used by the main demos with
install.packages(c("MASS", "bayesplot", "brms", "cmdstanr ", "dplyr", "gganimate", "ggdist", "ggforce", "ggplot2", "grid", "gridExtra", "latex2exp", "loo", "plyr", "posterior", "purrr", "rprojroot", "tidyr", "quarto"))
aaltobda packageThe course has its own R package aaltobda with data and
functionality to simplify coding. aaltobda has been
pre-installed in Aalto JupyterHub. To install the package to your own
computer just run the following (upgrade=”never” skips question about
updating other packages):
install.packages("remotes")remotes::install_github("avehtari/BDA_course_Aalto", subdir = "rpackage", upgrade="never", dependencies=TRUE)If during the course there is announcement that aaltobda
has been updated (e.g. some error has been fixed), you can get the
latest version by repeating the second step above.
Getting the setup needed for the course working on Windows might
involve a bit more effort than on Linux and Mac. Consequently,
we recommend using either Linux or MacOS, or using R
remotely. Moreover, Stan, the probabilistic
programming language which we will use later on during the course
requires a C++ compiler toolchain which is not available by default in
Windows (blame Microsoft). However, if you want to use Windows and have
a problem getting the setup working, below are two options to
consider:
knitrIf you just installed RStudio and R, chances are you don’t have
knitr installed, the package responsible for rendering your
notebook to pdf.
Solution:
install.packages("knitr")
You can also install packages from RStudio menu
Tools->Install Packages.
knitr is installed but the pdf won’t compileIn this case it is possible that you don’t have LaTeX installed, which is the package that runs the engine to process the text and render the pdf itself.
Solution: Tinytex is the bare minimum Latex core that you need to install in order to run the pdf compiler. If you want to go further and download a full distribution of Latex, look at TeX Live for Linux and MacTeX for Mac OS.
install.packages("tinytex")
tinytex::install_tinytex()
CmdStanR or
RStanCmdStanR is faster in use, and thus we
recommend using CmdStanR instead of RStan, but
both can be used for the assignments.CmdStanR is
a lightweight interface to Stan for R users (see CmdStanPy
for Python).CmdStanR avoids some installation problems as it
doesn’t require matching C++ tools for R and
RStanRStan along with the necessary C++ compiler
toolchain as described hereInstead of RStan, you can also use new CmdStanR which
maybe easier to install.
tidyr or tidyverse that is used in
the R demos? What does %>% mean?%>%|>, which in most cases can replace %>%,
and there are some differences only in more advanced use cases.ggplot2, can be
useful for visualizing results in the reports.Unfortunately the installation of pystan will fail on an
M1 Mac, as there is not a binary wheel available for the
httpstan dependency. A recommended alternative here is the
CmdStanPy package.
M1 Mac users that are intent on using pystan will need
to complete the following steps to build httpstan from
source and then install pystan:
httpstan# Download httpstan source
git clone https://github.com/stan-dev/httpstan
cd httpstan
# Build shared libraries and generate code
python3 -m pip install poetry
# Build httpstan source
# - There will be many compiler warnings, these are safe to ignore
make -j8
# Build the httpstan wheel
python3 -m poetry build
# Install the wheel
python3 -m pip install dist/*.whl
pystanpython3 -m pip install pystan
Here are some great Aalto courses that are using Bayesian inference